package com.hqyj.controller;


import com.hqyj.pojo.TbParking;
import com.hqyj.service.TbParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 车位表 前端控制器
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/tb-parking")
public class TbParkingController {

    @Autowired
    private TbParkingService parkingService;


    /**
     * 管理员新增某个小区的停车位
     * 127.0.0.1:8080/tb-parking/insertPark---post
     * {"conmunityName":"海棠苑","communityId":"1","picture":"","code":"01","name":"私家车位"}
     * @param tbParking
     * @return
     */
    @PostMapping(value = "/insertPark",consumes = "application/json")
    public HashMap<String, Object> insertPark(@RequestBody TbParking tbParking){
        return parkingService.insertPark(tbParking);
    }


    /**
     * 管理员修改某个小区的停车位
     * 127.0.0.1:8080/tb-parking/updatePark---put
     * {"id":"1","picture":"","code":"01","name":"私有车位","updateTime":""}
     * @param tbParking
     * @return
     */
    @PutMapping(value = "/updatePark",consumes = "application/json")
    public HashMap<String,Object> updatePark(@RequestBody TbParking tbParking){
        return  parkingService.updatePark(tbParking);
    }

    /**
     * 管理员删除一个停车位
     * 127.0.0.1:8080/tb-parking/deleteParking/{id} ---- delete
     * @param id
     * @return
     */
    @DeleteMapping(value = "/deleteParking/{id}")
    public HashMap<String, Object> deleteTbParking(@PathVariable Integer id){
        return parkingService.deletePark(id);
    }

    /**
     * 管理员查询所有的停车位(分页查询)
     * 127.0.0.1:8080/tb-parking/parks---get
     * @return
     */
    @GetMapping(value = "parks")
    public HashMap<String, Object> listPark(TbParking tbParking){
        return parkingService.listPark(tbParking);
    }

    /**
     * 查询所有可以购买的车位的车位编号
     * 127.0.0.1:8080/tb-parking/codes---get
     * @return
     */
    @GetMapping(value = "codes")
    public HashMap<String, Object> listCode(){
        return parkingService.listCode();
    }


}

